export enum QuestionType {
    TEXT = 'TEXT',
    DATE = 'DATE',
    TIME = 'TIME',
    SINGLE_CHOICE = 'SINGLE_CHOICE',
    MULTI_CHOICE = 'MULTI_CHOICE',
    IMAGE = 'IMAGE',
}
export const questionTypeToString = (t: QuestionType): string => {
    switch (t) {
        case QuestionType.TEXT: return '填空'
        case QuestionType.DATE: return '日期'
        case QuestionType.TIME: return '时间'
        case QuestionType.SINGLE_CHOICE: return '单选'
        case QuestionType.MULTI_CHOICE: return '多选'
        case QuestionType.IMAGE: return '图片'
    }
}
export type Template = {
    id: number,
    tableName: string,
    description: string,
    creationTime: string,
}
export type Question = {
    id: number,
    questionNumber: number,
    templateId: number,
    title: string,
    type: QuestionType,
}

export type QuestionChoice = {
    id: number,
    name: string,
    choiceNumber: number,
    questionId: number,
}

export type Approver = {
    approverId: number,
    number: number,
    templateId: number,
}

export type User = {
    id: number,
    nickname: string,
    role: RoleType,
    username: string,
    department: string
}

export enum RoleType {
    ADMIN = 'ADMIN',
    APPROVER = 'APPROVER',
    APPLICANT = 'APPLICANT',
}

export const roleTypeToString = (t?: RoleType): string => {
    switch (t) {
        case RoleType.ADMIN: return '管理员'
        case RoleType.APPROVER: return '审批人'
        case RoleType.APPLICANT: return '申请人'
    }
    return ''
}

export type Application = {
    id: number,
    applicationId: number,
    templateId: number,
    creationTime: string,
    confirmed: boolean,
}

export type Progress = {
    id: number,
    applicationId: number,
    approve: boolean,
    approverId: number,
    opinion: string,
    submitTime: string,
}

export type Answer = {
    id: number,
    applicationId: number,
    questionId: number,
    answer: string,
}

export type ApplicationQuestion = {
    question: Question,
    answer: Answer,
    choices: QuestionChoice[],
}

export enum Status {
    APPROVED = 'APPROVED',
    REJECTED = 'REJECTED',
    PENDING = 'PENDING',
}

export const statusToString = (t?: Status): string => {
    switch (t) {
        case Status.APPROVED: return '已同意'
        case Status.REJECTED: return '已拒绝'
        case Status.PENDING: return '待审批'
    }
    return ''
}

export type ApplicationInfo = {
    application: Application,
    approvers: Approver[],
    progress: Progress[],
    questions: ApplicationQuestion[],
    status: Status,
    template: Template,
    applicant: User,
    closed: boolean,
    canApprove: boolean,
}

export type ResourceResponse = {
    ok: boolean,
    length: number,
    sha: string,
    type: string,
}